package com.example.javaairportflightanalysis.dao.sql;

import cn.hutool.core.util.ObjectUtil;
import io.micrometer.common.util.StringUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.ibatis.jdbc.SQL;

public class AuditProvider {
    public String searchBy(String dfltFlno,Integer status){
        return new SQL() {{
            SELECT("DFLT_FLNO,DFLT_AWCD,APCD,DTIME,FPTT,FPLT,STATUS,Flight_Status,UUID");
            FROM("zbtj.Dfdl_Check_A");
            if (StringUtils.isNotBlank(dfltFlno)){
                WHERE("DFLT_FLNO = #{dfltFlno}");
            }
            if (!ObjectUtil.isNull(status)){
                WHERE("STATUS = #{status}");
            }
        }}.toString();
    }

    public String searchByTransferCheckA(String dfltFlno,Integer status){
        return new SQL(){{
            SELECT("DFLTFLNO,DFLTAWCD,APCD,DTIME,FPTT,FPLT,STATUS,Flight_Status,UUID");
            FROM("zbtj.Transfer_Check_A");
            if (StringUtils.isNotBlank(dfltFlno)){
                WHERE("DFLTFLNO = #{dfltFlno}");
            }
            if (!ObjectUtil.isNull(status)){
                WHERE("STATUS = #{status}");
            }
        }}.toString();
    }

    public String searchByDfdlCheckD(String dfltFlno,Integer status ){
        return new SQL(){{
            SELECT("DFLT_FLNO,DFLT_AWCD,APCD,DTIME,FPTT,FPLT,STATUS,Flight_Status,UUID");
            FROM("zbtj.Dfdl_Check_D");
            if (StringUtils.isNotBlank(dfltFlno)){
                WHERE("DFLT_FLNO = #{dfltFlno}");
            }
            if (!ObjectUtil.isNull(status)){
                WHERE("STATUS = #{status}");
            }
        }}.toString();
    }

    public String searchByTransferD(String dfltFlno,Integer status){
        return new SQL(){{
            SELECT("DFLTFLNO,DFLTAWCD,APCD,DTIME,FPTT,FPLT,STATUS,Flight_Status,UUID");
            FROM("zbtj.Transfer_Check_D");
            if (StringUtils.isNotBlank(dfltFlno)){
                WHERE("DFLTFLNO = #{dfltFlno}");
            }
            if (!ObjectUtil.isNull(status)){
                WHERE("STATUS = #{status}");
            }
        }}.toString();
    }

}
